const express = require('express');
const router = express.Router();
const paging = require("../paging/index")

//按地址查询
router.post('/local',async (req,res) => {
    let {town,village,community} = req.body
    if(!town){
        //无镇村社队，程序异常，阻止执行
        return res.send({
            code: 1,
            msg: '请输入镇'
        })
    }else if(!town && village){
        //有村，无镇
        return res.send({
            code: 1,
            msg: '请输入镇'
        })
    }else if(!town && !village && community){
        //有社，无镇村
        return res.send({
            code: 1,
            msg: '请输入镇，村'
        })
    }else if(!town && !village && !community ){
        //无镇村社，有队
        return res.send({
            code: 1,
            msg: '请输入镇，村，社'
        })
    }
    let obj = {town,village,community}
    await paging(req,res,obj)
})

//按用户编号查询
router.post('/userId',async (req,res) => {
    let {name} = req.body
    //如果没有传过来id，则返回参数错误
    if(!name){
        return res.send({
            code: 1,
            msg: '参数错误,请输入姓名'
        })
    }
    let obj = {
        name
    }
    //有id值
    await paging(req,res,obj)
})

//按园区查
router.post('/ground',async (req,res) => {
    let {groundCount} = req.body
    //如果没有传过来id，则返回参数错误
    if(!groundCount){
        return res.send({
            code: 1,
            msg: '参数错误,请输入姓名'
        })
    }
    let obj = {
        groundCount
    }
    //有id值
    await paging(req,res,obj)
})

module.exports = router
